package cel;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * This tests for variability in bullet power administered by the robot DaCruzer.
 * 
 * @author Philip Johnson
 */
public class TestWayFarerHitEnemy extends RobotTestBed {
  // True if WayFarer has fired a bullet that hit an enemy;
  boolean bulletHitEnemy = false;

  /**
   * Specifies that SittingDuck and WayFarer are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,cel.WayFarer";
  }

  /**
   * This test runs for 20 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 20;
  }

  /**
   * At the end of each turn, to see if the bullet shot hits an enemy.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // All active bullets belong to WayFarer since SittingDuck does not fire.
    IBulletSnapshot bullets[] = event.getTurnSnapshot().getBullets();
    boolean bulletPower;
    for (int i = 0; i < bullets.length; i++) {
      // Checks to see if the bullet hits the enemy (explodes).
      bulletPower = bullets[i].isExplosion();
      if (bulletPower) {
        bulletHitEnemy = true;
      }
    }
  }

  /**
   * After running all matches, determine if DaCruzer has had variability in its bullet power.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Bullet hit an enemy", bulletHitEnemy);
  }
}